<?php
$r_url = "admin.php?file=gamesys";
#[判断权限]
if($_SESSION["admin"]["typer"] != "system" && !$QG_AP["users"]&& !$QG_AP["games"])
{
	Error("对不起，您没有权限操作当前功能","admin.php?file=index");
}
if($sysact == "add" || $sysact == "modify")
{
	if($sysAct == "modify")
	{
		$id = intval($id);
		if(!$id)
		{
			Error("操作非法！","admin.php?file=gamesys&act=list");
		}
		$rs = $DB->qgGetOne("SELECT * FROM e_mail WHERE id='".$id."'");
	
	}
}
elseif($sysact == "viewok")
{
	$id = intval($id);
	$msg = $STR->safe($_POST);
	if($id)
	{
		$sql = "UPDATE e_mail SET e_name='".$msg["e_name"]."',e_username='".$msg["e_username"]."',e_title='".$msg["e_title"]."',e_text='".$msg["e_text"]."',e_times='".strtotime($msg["e_times"])."',e_read='".$msg["e_read"]."' WHERE id='".$id."'";
		$DB->qgQuery($sql);		
		$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
		Error("信息编辑成功",$r_url."&act=list");
	}
	else
	{
		$sql = "SELECT username FROM ".$prefix."e_mail WHERE username='".$msg["username"]."'";
		$rschk = $DB->qgGetOne($sql);
		if($rschk)
		{
			Error("城池名称 ".$msg["username"]." 已经存在",$r_url."&act=add");
		}
		$sql = "INSERT INTO ".$prefix."e_mail(id,e_name,e_username,e_title,e_text,e_times,e_read,notice,e_type) VALUES('','".$msg["e_name"]."','".$msg["e_username"]."','".$msg["e_title"]."','".$msg["e_text"]."','".strtotime($msg["e_times"])."','".$msg["e_read"]."','1','2')";
		$DB->qgQuery($sql);
		Error("信息添加成功",$r_url."&act=list");
	}
}
elseif($sysact == "delete")
{
	$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
	$id = intval($id);
	if(!$id)
	{
		Error("操作非法",$r_url);
	}
	$sql = "DELETE FROM ".$prefix."e_mail WHERE c_id='".$id."'";
	$DB->qgQuery($sql);
	Error("任务信息删除成功",$r_url);
}
elseif($sysact == "deleteall")
{
	$r_url = $_SESSION["return_url"] ? $_SESSION["return_url"] : $r_url."&act=list";
	$sql = "TRUNCATE TABLE `e_mail`";
	$DB->qgQuery($sql);
	Error("所有信息删除成功",$r_url);
}
elseif($act == "list")
{
	$page_url = "admin.php?file=gamesys&act=list";
	$psize = 20;
	$pageid = intval($pageid);
	$offset = $pageid>0 ? ($pageid-1)*$psize : 0;
	$condition = "WHERE 1";
	$keywords = SafeHtml($keywords);
	$stype = SafeHtml($stype);
	if($keywords)
	{
		if($stype == "e_username")
		{
			$condition .= " AND e_username LIKE '%".$keywords."%'";
		}
		elseif($stype == "e_name")
		{
			$condition .= " AND e_name LIKE '%".$keywords."%'";
		}
		
		$page_url .= "&stype=".rawurlencode($stype)."&keywords=".rawurlencode($keywords);
	}
	$count = $DB->qg_count("SELECT count(id) FROM ".$prefix."e_mail ".$condition);
	$pagelist = page($page_url,$count,$psize,$pageid);#[获取页数信息]
	$rslist = $DB->qgGetAll("SELECT *  FROM ".$prefix."e_mail ".$condition." ORDER BY id DESC LIMIT ".$offset.",".$psize);
}
Foot("gamesys.qg");
?>